/// <reference path="../../base/device/BaseDevice.ts" />
namespace mplat {
    export class WxDevice extends BaseDevice {

        protected _isVibrateOn = true;
        protected _vibrate_local_key_ = '_vibrate_local_key_'

        constructor() {
            super();
            this._init();
        }

        protected _init() {
            timerOnce(16, this, () => {
                let vibStr = this.getStorage(this._vibrate_local_key_);
                if (!vibStr) {
                    this._isVibrateOn = true;
                } else {
                    this._isVibrateOn = vibStr == '1' ? true : false;
                }
            })

        }

        setClipboardData(data: any, success?: (res?) => void): void {
            if (!wx['setClipboardData']) return;
            wx.setClipboardData({
                data,
                success
            })
        }
        getClipboardData(success: (res: any) => void): void {
            if (!wx['getClipboardData']) return;
            wx['getClipboardData']({
                success
            })
        }

        setVibrateOn(vibrateOn: boolean): void {
            this._isVibrateOn = vibrateOn;
            timerOnce(16, this, () => {
                let data = vibrateOn ? '1' : '0';
                this.setStorage(this._vibrate_local_key_, data);
            })
        }
        get isVibrateOn() {
            return this._isVibrateOn;
        }
        vibrateLong(): void {
            if (!this._isVibrateOn) return;
            if (wx['vibrateLong']) {
                wx['vibrateLong']();
            }
        }
        vibrateShort(): void {
            if (!this._isVibrateOn) return;
            if (wx['vibrateShort']) {
                wx['vibrateShort']();
            }
        }

        setKeepScreenOn(keepScreenOn: boolean): void {
            if (wx["setKeepScreenOn"]) {
                wx["setKeepScreenOn"]({ keepScreenOn });
            }
        }
    }
}